package com.ruoyi.womp.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ruoyi.womp.service.ISqlQueryService;
import com.ruoyi.womp.tools.DateUtil;

@Component("sysLogDataTask")
public class SysLogDataTask {

	final static String TASK_NAME = "系统日志数据清理任务";

	@Autowired
	ISqlQueryService sqlQueryService;

	public void execute() {
		handleData();
	}

	private void handleData() {
		try {

			String sql = "select config_value from sys_config where config_key='sys_log_save_days'";
			Integer days = sqlQueryService.getInteger(sql);

			String date = DateUtil.dateAddDay(-days, "yyyy-MM-dd");
			date += " 23:59:59";

			sql = " delete from sys_job_log where create_time<'" + date + "'";
			sqlQueryService.executeSql(sql);
			// 删除数据
			System.out.println(date);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}